﻿using UnityEngine;
using System.Collections.Generic;
using Dict.DataModel;

namespace Dict.Blo
{
    public class DictFieldResourcePosBlo
    {
        static public List<TableFieldResourcePos> GetAll()
        {
            return Dict.DictDataManager.Instance.tableFieldResourcePosDao.CacheList;
        }

        static public List<TableFieldResourcePos> GetAllFishPos()
        {
            List<TableFieldResourcePos> fishs = new List<TableFieldResourcePos>();
            foreach(var fish in GetAll())
            {
                if(fish.posId.StartsWith("fish_pos_"))
                {
                    fishs.Add(fish);
                }
            }
            return fishs;
        }

        static public List<TableFieldResourcePos> GetAllMinePos()
        {
            List<TableFieldResourcePos> fishs = new List<TableFieldResourcePos>();
            foreach (var fish in GetAll())
            {
                if (fish.posId.StartsWith("mine_pos_"))
                {
                    fishs.Add(fish);
                }
            }
            return fishs;
        }
        
        static public TableFieldResourcePos GetOne(string id)
        {
            return Dict.DictDataManager.Instance.tableFieldResourcePosDao.GetById(id);
        }
        
        static public Vector3 GetPosition(string id)
        {
            var pos = GetOne(id);
            var sss = pos.pos.Trim().Split(new char[1] { ',' }, System.StringSplitOptions.RemoveEmptyEntries);
            var x = float.Parse(sss[0]);
            var y = float.Parse(sss[1]);
            var z = float.Parse(sss[2]);

            return new Vector3(x, y, z);
        }

        static public float GetAngle(string id)
        {
            var pos = GetOne(id);
            return (float)pos.angle;
        }
        
    }
}